# -*- coding: utf-8 -*-

import wordProcessor

class Stemmer(wordProcessor.WordProcessor) :
    """Stemming is done in the following way: if the processed word has one of endings occuring in endings file, the ending is chopped. Otherwise nothing is done."""

    ending_list = []
    
    def __init__(self, filename='endings.txt') :
        endings = open(filename, 'r')
        for line in endings :
            line = line.strip()
            self.ending_list.append((len(line), line))
        endings.close()
        
    def process(self, word) :
        for end_len, ending in self.ending_list :
            if len(word) > end_len :
                if (word[-end_len:] == ending) :
                    return word[:-end_len]
        return word
        
if __name__ == "__main__" :
    s = Stemmer()
    print s.process('chińskiego')
